package com.korubo.web.contrller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.korubo.kit.R;
import com.korubo.web.model.Order;
import com.korubo.web.service.OrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (tb_order)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    //list
    @PostMapping("list")
    public R list(@RequestBody(required = false) Order order) {
        return orderService.list(order);
    }

    @PostMapping("add")
    public R add(@RequestBody Order order) {
        order.setId(UUID.fastUUID().toString());
        order.setCreateTime(DateUtil.now());
        return orderService.save(order) ? R.ok() : R.fail();
    }

    @PostMapping("update")
    public R update(@RequestBody Order order) {
        return orderService.updateById(order) ? R.ok() : R.fail();
    }

    @PostMapping("delete")
    public R delete(@RequestBody Order order) {
        return orderService.removeById(order.getId()) ? R.ok() : R.fail();
    }

    @PostMapping("findById")
    public R findById(@RequestBody Order order) {
        return R.ok(orderService.getById(order.getId()));
    }

}
